package com.ms.oschina.fragment;

import java.io.IOException;
import java.util.List;

import com.ms.oschina.adapter.FavoriteAdapter;
import com.ms.oschina.adapter.PageIndexListAdapter;
import com.ms.oschina.api.remote.OsChinaApi;
import com.ms.oschina.base.BaseListFragment;
import com.ms.oschina.bean.Favorite;

public class FavoriteInfoFragment extends BaseListFragment<Favorite> {

	private FavoriteAdapter adapter;

	@Override
	public PageIndexListAdapter<Favorite> getAdapter() {
		adapter = new FavoriteAdapter(getListView(), getNetData(), true);
		int mark = getMark();
		adapter.setMark(mark);
		return adapter;
	}

	@Override
	protected void setEvent() {
	}

	@Override
	public List<Favorite> getNetData(int pageIndex) throws IOException {
		int mark = getMark();
		switch (mark) {
		case FavoriteFragment.SOFTWARE:
			return OsChinaApi.getFavoriteInfo(pageIndex,
					Favorite.CATALOG_SOFTWARE);
		case FavoriteFragment.TOPICS:
			return OsChinaApi
					.getFavoriteInfo(pageIndex, Favorite.CATALOG_TOPIC);
		case FavoriteFragment.Code:
			return OsChinaApi.getFavoriteInfo(pageIndex, Favorite.CATALOG_CODE);
		case FavoriteFragment.Blog:
			return OsChinaApi
					.getFavoriteInfo(pageIndex, Favorite.CATALOG_BLOGS);
		case FavoriteFragment.INFORMATION:
			return OsChinaApi.getFavoriteInfo(pageIndex, Favorite.CATALOG_NEWS);
		default:
			return null;
		}
	}
}
